home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- import simplejson
-
- def serialize(thing):
- if type(thing) is dict:
- return dict((lambda .0: for a, b in .0:
- (serialize(a), serialize(b)))(thing.iteritems()))
- elif isinstance(thing, str):
- return '__str__' + thing
- elif isinstance(thing, unicode):
- return '__unicode__' + thing
- elif isinstance(thing, bool):
- if thing:
- return '__True__'
- else:
- return '__False__'
- elif isinstance(thing, (int, long)):
- return '__int__' + str(thing)
- elif isinstance(thing, float):
- return '__float__' + repr(thing)
- elif isinstance(thing, type(None)):
- return '__None__'
- elif type(thing) is tuple:
- return {
- '__tuple__': list((lambda .0: for foo in .0:
- serialize(foo))(thing)) }
- elif type(thing) is list:
- return list((lambda .0: for foo in .0:
- serialize(foo))(thing))
- elif type(thing) is set:
- []['__set__'] = [ serialize(foo) for foo in sorted(thing) ]
- return []
- elif type(thing) is frozenset:
- []['__frozenset__'] = [ serialize(foo) for foo in sorted(thing) ]
- return []
-
-
-
- def unserialize(thing):
- if type(thing) is unicode:
- if thing.startswith('__str__'):
- return str(thing[7:])
-
- if thing.startswith('__unicode__'):
- return unicode(thing[11:])
-
- if thing.startswith('__int__'):
- return int(thing[7:])
-
- if thing.startswith('__float__'):
- return float(thing[9:])
-
- if thing == '__None__':
- return None
-
- if thing == '__True__':
- return True
-
- if thing == '__False__':
- return False
-
- return thing
-
- if type(thing) is dict:
- return dict((lambda .0: for foo, bar in .0:
- (unserialize(foo), unserialize(bar)))(thing.iteritems()))
- elif type(thing) is set:
- return set((lambda .0: for foo in .0:
- unserialize(foo))(thing))
- elif type(thing) is frozenset:
- return frozenset((lambda .0: for foo in .0:
- unserialize(foo))(thing))
- elif type(thing) is tuple:
- return tuple((lambda .0: for foo in .0:
- unserialize(foo))(thing))
- elif type(thing) is list:
- return list((lambda .0: for foo in .0:
- unserialize(foo))(thing))
-
-
-
- def untupleset(obj):
- if '__tuple__' in obj:
- return tuple(obj['__tuple__'])
- elif '__set__' in obj:
- return set(obj['__set__'])
- elif '__frozenset__' in obj:
- return frozenset(obj['__frozenset__'])
-
- return obj
-
-
- def pydumps(obj):
- return simplejson.dumps(serialize(obj), sort_keys = True, separators = (',', ':'))
-
-
- def pyloads(obj):
- return unserialize(simplejson.loads(obj, object_hook = untupleset))
-
- __all__ = [
- 'pydumps',
- 'pyloads']
- if __name__ == '__main__':
- pass
-
-